<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const isLoading = ref(true)
const userInfo = ref({
  username: '',
  level: 60,
  gameTime: '168小时',
  shikigamiCount: 120,
  achievements: 45,
  recentActivities: []
})

// 游戏数据
const gameData = ref({
  characters: [
    {
      id: 1,
      name: '晴明',
      avatar: '晴明',
      level: 60,
      rarity: 'SSR',
      skills: ['言灵·守', '言灵·星', '技能3']
    },
    {
      id: 2,
      name: '茨木童子',
      avatar: '茨木',
      level: 50,
      rarity: 'SSR',
      skills: ['鬼手', '罗生门', '技能3']
    },
    {
      id: 3,
      name: '不知火',
      avatar: '不知火',
      level: 55,
      rarity: 'SSR',
      skills: ['离影', '蝶步', '技能3']
    }
  ],
  recentGames: [
    {
      id: 1,
      date: '2023-09-01',
      type: '探索',
      result: '成功',
      rewards: ['勾玉 x20', '金币 x1000']
    },
    {
      id: 2,
      date: '2023-08-31',
      type: '魂十',
      result: '成功',
      rewards: ['暴击御魂', '金币 x500']
    },
    {
      id: 3,
      date: '2023-08-30',
      type: '斗技',
      result: '胜利',
      rewards: ['斗技点数 x50', '荣誉值 x20']
    }
  ],
  achievements: [
    {
      id: 1,
      title: '初入平安京',
      description: '完成新手引导',
      unlocked: true
    },
    {
      id: 2,
      title: '百鬼夜行',
      description: '收集100个式神',
      unlocked: true
    },
    {
      id: 3,
      title: '阴阳师大人',
      description: '达到60级',
      unlocked: true
    },
    {
      id: 4,
      title: '鬼王终结者',
      description: '击败所有鬼王',
      unlocked: false
    }
  ],
  ongoingEvents: [
    {
      id: 1,
      title: '宇智月活动',
      description: '参与活动收集限定道具',
      endDate: '2023-09-15',
      progress: 75
    },
    {
      id: 2,
      title: 'SSR召唤概率UP',
      description: '限定时间内SSR召唤概率提升',
      endDate: '2023-09-10',
      progress: 50
    }
  ]
})

// 模拟数据加载
onMounted(() => {
  // 从localStorage获取用户信息
  const savedUser = localStorage.getItem('currentUser')
  if (savedUser) {
    userInfo.value.username = JSON.parse(savedUser).username
  }
  
  setTimeout(() => {
    isLoading.value = false
  }, 500)
})

// 处理退出登录
const handleLogout = () => {
  localStorage.removeItem('currentUser')
  router.push('/onmyoji')
}
</script>

<template>
  <div class="game-center-container">
    <!-- 顶部导航 -->
    <header class="game-center-header">
      <div class="header-content">
        <svg class="netease-logo" viewBox="0 0 100 30" width="100" height="30">
          <rect width="100" height="30" fill="#0d0d0d" rx="4" ry="4" />
          <text x="50" y="20" font-family="Arial, sans-serif" font-size="14" font-weight="bold" fill="#d4af37" text-anchor="middle">网易游戏</text>
        </svg>
        <nav class="main-nav">
          <ul class="nav-menu">
            <li><a href="#" @click.prevent="router.push('/onmyoji')" class="nav-link">返回游戏官网</a></li>
          </ul>
        </nav>
        <button class="logout-btn" @click="handleLogout">退出登录</button>
      </div>
    </header>

    <!-- 主内容区 -->
    <main class="game-center-main" v-if="!isLoading">
      <!-- 页面标题 -->
      <div class="game-center-header-section">
        <h1 class="game-center-title">游戏中心</h1>
      </div>
      <!-- 玩家信息卡片 -->
      <div class="player-card">
        <div class="player-avatar">
          <svg width="80" height="80" viewBox="0 0 80 80">
            <circle cx="40" cy="40" r="35" fill="#1a1a1a" stroke="#d4af37" stroke-width="2"/>
            <text x="40" y="45" font-family="Arial" font-size="20" fill="#d4af37" text-anchor="middle">{{ userInfo.username.charAt(0) }}</text>
          </svg>
        </div>
        <div class="player-info">
          <h2>{{ userInfo.username }}</h2>
          <div class="player-stats">
            <div class="stat">
              <span class="stat-value">{{ userInfo.level }}</span>
              <span class="stat-label">等级</span>
            </div>
            <div class="stat">
              <span class="stat-value">{{ userInfo.gameTime }}</span>
              <span class="stat-label">游戏时长</span>
            </div>
            <div class="stat">
              <span class="stat-value">{{ userInfo.shikigamiCount }}</span>
              <span class="stat-label">式神数量</span>
            </div>
            <div class="stat">
              <span class="stat-value">{{ userInfo.achievements }}</span>
              <span class="stat-label">成就</span>
            </div>
          </div>
        </div>
      </div>

      <!-- 内容网格 -->
      <div class="content-grid">
        <!-- 游戏角色 -->
        <div class="content-card">
          <h3>我的角色</h3>
          <div class="character-list">
            <div class="character-card" v-for="character in gameData.characters" :key="character.id">
              <div class="character-avatar">
                <svg width="60" height="60" viewBox="0 0 60 60">
                  <circle cx="30" cy="30" r="28" fill="#1a1a1a" stroke="#d4af37" stroke-width="2"/>
                  <text x="30" y="35" font-family="Arial" font-size="16" fill="#d4af37" text-anchor="middle">{{ character.avatar }}</text>
                </svg>
              </div>
              <div class="character-info">
                <h4>{{ character.name }}</h4>
                <p>{{ character.rarity }} · Lv.{{ character.level }}</p>
              </div>
            </div>
          </div>
        </div>

        <!-- 最近游戏记录 -->
        <div class="content-card">
          <h3>最近游戏</h3>
          <div class="game-records">
            <div class="record-item" v-for="record in gameData.recentGames" :key="record.id">
              <div class="record-date">{{ record.date }}</div>
              <div class="record-info">
                <p>{{ record.type }}</p>
                <p class="record-result" :class="record.result === '成功' || record.result === '胜利' ? 'success' : 'fail'">
                  {{ record.result }}
                </p>
              </div>
              <div class="record-rewards">
                <p>{{ record.rewards.join(', ') }}</p>
              </div>
            </div>
          </div>
        </div>

        <!-- 成就系统 -->
        <div class="content-card">
          <h3>成就进度</h3>
          <div class="achievement-list">
            <div class="achievement-item" v-for="achievement in gameData.achievements" :key="achievement.id">
              <div class="achievement-info">
                <h4>{{ achievement.title }}</h4>
                <p>{{ achievement.description }}</p>
              </div>
              <div class="achievement-status">
                <span v-if="achievement.unlocked" class="unlocked">✓ 已解锁</span>
                <span v-else class="locked">○ 未解锁</span>
              </div>
            </div>
          </div>
        </div>

        <!-- 活动进行中 -->
        <div class="content-card">
          <h3>进行中活动</h3>
          <div class="event-list">
            <div class="event-item" v-for="event in gameData.ongoingEvents" :key="event.id">
              <div class="event-info">
                <h4>{{ event.title }}</h4>
                <p>{{ event.description }}</p>
                <p class="event-date">截止: {{ event.endDate }}</p>
              </div>
              <div class="event-progress">
                <div class="progress-bar">
                  <div class="progress-fill" :style="{ width: event.progress + '%' }"></div>
                </div>
                <span class="progress-text">{{ event.progress }}%</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </main>

    <!-- 加载状态 -->
    <div class="loading-container" v-else>
      <div class="loading-spinner"></div>
      <p>加载游戏数据中...</p>
    </div>
  </div>
</template>

<style scoped>
/* 使用全局CSS变量 - 已在App.vue中定义 */

.game-center-container {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--bg-primary), #1a0f2e);
  background-color: rgba(26, 15, 46, 0.7); /* 降低背景透明度 */
  color: var(--text-primary);
  font-family: 'Arial', sans-serif;
}

/* 头部导航 */
.game-center-header {
  background: rgba(0, 0, 0, 0.9);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 15px 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.netease-logo {
  cursor: pointer;
}

.main-nav .nav-menu {
  display: flex;
  list-style: none;
  gap: 30px;
}

.nav-link {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.3s;
  font-size: 14px;
}

.nav-link:hover {
  color: var(--gold-primary);
}

.logout-btn {
  padding: 8px 20px;
  background: rgba(212, 175, 55, 0.1);
  border: 1px solid var(--gold-primary);
  border-radius: 4px;
  color: var(--gold-primary);
  cursor: pointer;
  transition: all 0.3s;
  font-size: 14px;
}

.logout-btn:hover {
  background: rgba(212, 175, 55, 0.2);
  box-shadow: 0 0 10px rgba(212, 175, 55, 0.3);
}

/* 主内容区 */
.game-center-header-section {
  text-align: center;
  margin-bottom: 60px;
}

.game-center-title {
  font-size: 48px;
  font-weight: bold;
  font-family: 'Ma Shan Zheng', cursive;
  letter-spacing: 5px;
  background: linear-gradient(45deg, var(--purple-light), var(--gold-primary), var(--purple-mid));
  background-size: 200% 200%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: 1px rgba(255, 255, 255, 0.3);
  text-stroke: 1px rgba(255, 255, 255, 0.3);
  text-shadow: 0 0 20px rgba(138, 43, 226, 0.6), 0 0 30px rgba(212, 175, 55, 0.4);
  animation: gradientAnimation 6s ease infinite, pulse 4s ease-in-out infinite;
}

.game-center-main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 30px;
}

/* 玩家信息卡片 */
.player-card {
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 30px;
  margin-bottom: 30px;
  display: flex;
  align-items: center;
  gap: 30px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.player-avatar {
  flex-shrink: 0;
}

.player-info h2 {
  margin: 0 0 20px 0;
  color: var(--gold-primary);
  font-size: 28px;
}

.player-stats {
  display: flex;
  gap: 40px;
}

.stat {
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 24px;
  font-weight: bold;
  color: var(--gold-primary);
  margin-bottom: 5px;
}

.stat-label {
  font-size: 14px;
  color: var(--text-secondary);
}

/* 内容网格 */
.content-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 30px;
}

.content-card {
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 25px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  transition: transform 0.3s, box-shadow 0.3s;
}

.content-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 30px rgba(212, 175, 55, 0.15);
}

.content-card h3 {
  margin: 0 0 20px 0;
  color: var(--gold-primary);
  font-size: 20px;
  position: relative;
  padding-bottom: 10px;
}

.content-card h3::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 60px;
  height: 2px;
  background: var(--gold-primary);
}

/* 角色列表 */
.character-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.character-card {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 15px;
  background: var(--bg-secondary);
  border-radius: 8px;
  transition: all 0.3s;
}

.character-card:hover {
  background: var(--bg-light);
  transform: translateX(5px);
}

.character-info h4 {
  margin: 0 0 5px 0;
  color: var(--gold-primary);
  font-size: 16px;
}

.character-info p {
  margin: 0;
  font-size: 14px;
  color: var(--text-secondary);
}

/* 游戏记录 */
.game-records {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.record-item {
  padding: 15px;
  background: var(--bg-secondary);
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.record-date {
  font-size: 14px;
  color: var(--text-secondary);
  min-width: 100px;
}

.record-info {
  flex: 1;
  margin: 0 20px;
}

.record-info p:first-child {
  margin: 0 0 5px 0;
  font-size: 16px;
  color: var(--text-primary);
}

.record-result {
  margin: 0;
  font-size: 14px;
  font-weight: bold;
}

.record-result.success {
  color: #4CAF50;
}

.record-result.fail {
  color: #F44336;
}

.record-rewards {
  font-size: 14px;
  color: var(--text-secondary);
  text-align: right;
}

/* 成就列表 */
.achievement-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.achievement-item {
  padding: 15px;
  background: var(--bg-secondary);
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.achievement-info h4 {
  margin: 0 0 5px 0;
  font-size: 16px;
  color: var(--text-primary);
}

.achievement-info p {
  margin: 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.achievement-status {
  font-size: 14px;
  font-weight: bold;
}

.achievement-status.unlocked {
  color: #4CAF50;
}

.achievement-status.locked {
  color: var(--text-muted);
}

/* 活动列表 */
.event-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.event-item {
  padding: 20px;
  background: var(--bg-secondary);
  border-radius: 8px;
}

.event-info h4 {
  margin: 0 0 10px 0;
  font-size: 16px;
  color: var(--gold-primary);
}

.event-info p {
  margin: 5px 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.event-date {
  color: var(--text-muted) !important;
  font-size: 12px !important;
}

.event-progress {
  margin-top: 15px;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--bg-light);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 5px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold-primary), var(--gold-secondary));
  border-radius: 4px;
  transition: width 0.5s ease;
}

.progress-text {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: right;
  display: block;
}

/* 加载状态 */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 500px;
  color: var(--text-secondary);
}

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 3px solid var(--border-color);
  border-top: 3px solid var(--gold-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 20px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* 响应式设计 */
@media (max-width: 1024px) {
  .content-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    gap: 20px;
    text-align: center;
  }
  
  .game-center-title {
    font-size: 36px;
    letter-spacing: 3px;
  }
  
  .player-card {
    flex-direction: column;
    text-align: center;
  }
  
  .player-stats {
    justify-content: center;
    gap: 20px;
  }
  
  .main-nav .nav-menu {
    gap: 15px;
  }
  
  .record-item,
  .achievement-item {
    flex-direction: column;
    gap: 10px;
    text-align: center;
  }
  
  .record-date,
  .record-rewards {
    text-align: center;
  }
}

/* 渐变动画 */
@keyframes gradientAnimation {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

/* 文字呼吸动画 */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.9;
    transform: scale(1.03);
  }
}
</style>